@using OrchardCore.Autoroute.ViewModels;
@model AutoroutePartViewModel
@inject IAuthorizationService AuthorizationService
@inject OrchardCore.Settings.ISiteService SiteService
@{
    var site = await SiteService.GetSiteSettingsAsync();
}

<div class="form-group" asp-validation-class-for="Path">
    <label asp-for="Path">@T["Permalink"]</label>
    <div class="input-group">
        @if (!String.IsNullOrWhiteSpace(site.BaseUrl))
        {
            <div class="input-group-prepend">
                <div class="input-group-text">@site.BaseUrl</div>
            </div>
        }
        <input asp-for="Path" class="form-control" disabled="@(!Model.Settings.AllowCustomPath)" />
        <span asp-validation-for="Path"></span>
    </div>
    @if (!String.IsNullOrWhiteSpace(Model.Settings.Pattern) && Model.Settings.AllowCustomPath)
    {
        <span class="hint">@T["The url of the content item. Leave empty to auto-generate it."]</span>
    }
    else
    {
        <span class="hint">@T["The url of the content item. It will be automatically generated."]</span>
    }
</div>
@{
    var authorized = await AuthorizationService.AuthorizeAsync(User, Permissions.SetHomepage);
    var showHomepageOption = Model.Settings.ShowHomepageOption && authorized;

    if (Model.IsHomepage)
    {
        <div class="alert alert-info">@T["This content item is the current homepage"]</div>
    }
    else
    {
        if (showHomepageOption)
        {
            <fieldset class="form-group">
                <div class="custom-control custom-checkbox">
                    <input type="checkbox" class="custom-control-input" asp-for="SetHomepage" checked="@Model.SetHomepage" />
                    <label class="custom-control-label" asp-for="SetHomepage">@T["Set as homepage"]</label>
                    <span class="hint">@T["— {0}", "Check to set this content item as the homepage once published."]</span>
                </div>
            </fieldset>
        }
    }
}

@if (Model.Settings.AllowUpdatePath)
{
    <div class="form-group">
        <div class="custom-control custom-checkbox">
            <input type="checkbox" class="custom-control-input" asp-for="UpdatePath" checked="@Model.UpdatePath" />
            <label class="custom-control-label" asp-for="UpdatePath">@T["Refresh the path"]</label>
            <span class="hint">@T["— {0}", "Check to refresh the path. Warning: the previous URL won't be accessible anymore."]</span>
        </div>
    </div>
}
